package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.vo.AttributeListItemVO;
import cn.tedu.csmall.product.pojo.vo.BrandListItemVO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.service.IAttributeService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "02. 属性管理模块")
@Validated
@RestController
@RequestMapping("/attributes")
public class AttributeController {
    @Autowired
    IAttributeService attributeService;

    public AttributeController() {
        System.out.println("创建控制器类对象：AttributeController");
    }

    // http://localhost:8080/attributes/delete
    @ApiOperation("删除属性")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "属性牌id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public String delete(@PathVariable Long id){
        log.debug("开始处理【删除属性】的请求，参数：{}" , id);
        attributeService.deleteById(id);
        return "ok";
    }

    // http://localhost:9080/attributes
    @ApiOperation("查询属性列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<AttributeListItemVO>> list() {
        log.debug("开始处理【查询属性列表】的请求……");
        List<AttributeListItemVO> list = attributeService.list();
        return JsonResult.ok(list);
    }

}
